<template>
	<view class="user">
		<view class="head clearfix">
			<view class="left fl clearfix">
				<image :src="user_image" class="fl"></image>
				<view class="wenzi fl">
					<view class="name">Hi~</view>
					<view class="desc">ID:{{member_card}}</view>
				</view>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<view class="right fr" @click="qiehuan">切换代理</view>
			<!-- #endif -->
		</view>
		<view class="content">
			<view class="top clearfix">
				<image :src="baseUrl + '/wximage/user_qianbao.png'" class="fl"></image>
				<view class="title fl">我的钱包</view>
			</view>
			<view class="bottom clearfix">
				<view class="list fl" @click="topage('/pages/user/wallet')">
					<view class="zuo fl">
						<view class="name">押金</view>
						<view class="money">{{freez_balance}}<text>元</text></view>
					</view>
					<view class="you fr">
						<image :src="baseUrl + '/wximage/user_yajin.png'"></image>
					</view>
				</view>
				<view class="list fl" @click="topage('/pages/user/coupons')">
					<view class="zuo fl">
						<view class="name">优惠券</view>
						<view class="money">{{daijinquan}}<text>张</text></view>
					</view>
					<view class="you fr">
						<image :src="baseUrl + '/wximage/user_youhuiquan.png'"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="nav">
			<view class="top clearfix">
				<image :src="baseUrl + '/wximage/user_fuwu.png'" class="fl"></image>
				<view class="title fl">我的服务</view>
			</view>
			<view class="fenlei clearfix">
				<!-- <view class="li fl">
					<image :src="baseUrl + '/wximage/user_shangpindan.png'"></image>
					<view class="title">商品单</view>
				</view> -->
				<view class="li fl" @click="topage('/pages/order/index')">
					<image :src="baseUrl + '/wximage/user_order.png'"></image>
					<view class="title">充电单</view>
				</view>
				<view class="li fl" @click="topage('/pages/user/question')">
					<image :src="baseUrl + '/wximage/user_question.png'"></image>
					<view class="title">常见问题</view>
				</view>
				<view class="li fl" @click="call">
					<image :src="baseUrl + '/wximage/user_kefu.png'"></image>
					<view class="title">联系客服</view>
				</view>
				<view class="li fl" @click="topage('/pages/user/joinus')">
					<image :src="baseUrl + '/wximage/user_jiameng.png'"></image>
					<view class="title">加盟合作</view>
				</view>
				<view class="li fl" @click="topage('/pages/user/about')">
					<image :src="baseUrl + '/wximage/user_about.png'"></image>
					<view class="title">关于我们</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				x_tell: '',
				user_image: '',
				nickname: '',
				member_card: '',
				daijinquan: 0,
				freez_balance: 0,
			}
		},
		onLoad() {
			//获取基本配置信息
			this.request({
				url: '/xcx/webconfig',
				data: {}
			}).then(res => {
				if (res.data.code == 200) {
					this.x_tell = res.data.data.x_tell;
					this.user_image = res.data.data.user_image;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
			
			let user_id = uni.getStorageSync('user_id');
			
			this.request({
				url: '/xcx/users',
				data: {
					id: user_id,
				},
				method: "POST"
			}).then(res => {
				if (res.data.code == 200) {
					this.nickname = res.data.data.nick_name;
					this.member_card = res.data.data.member_card;
					if(res.data.data.freez_balance != null){
						this.freez_balance = res.data.data.freez_balance;
					}
				}
			})
			
			// 获取优惠券总数
			this.request({
				url: '/xcx/couponstj',
				data: {
					user_id: uni.getStorageSync('user_id'),
				},
				method: "POST"
			}).then(res => {
				if (res.data.code == 200) {
					this.daijinquan = res.data.data.wshiyong;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
		},
		methods:{
			call() {
				let tell = this.x_tell;
				uni.makePhoneCall({
					phoneNumber: tell,
					success(res) {
			
					},
					fail(res) {
			
					}
				})
			},
			qiehuan(){
				if(uni.getStorageSync('agent_id')){
					uni.navigateTo({
						url: '/subpackageA/index/index'
					})
				}else{
					uni.navigateTo({
						url: '/subpackageA/user/second/login'
					})
				}
			},
			topage(url){
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: #F8F8F8;
	}
	
	.user{
		width: 100%;
		margin: 0 auto;
		
		
		.head{
			width: 90%;
			margin: 0 auto;
			padding-top: 60rpx;
			
			.left{
				
				image{
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					margin-right: 30rpx;
				}
				
				.wenzi{
					margin-top: 14rpx;
					
					.name{
						font-size: 32rpx;
						font-weight: 700;
						color: #333333;
					}
					
					.desc{
						font-size: 24rpx;
						color: #999999;
					}
				}
			}
			
			.right{
				font-size: 24rpx;
				color: #DCAF86;
				height: 100rpx;
				line-height: 100rpx;
			}
		}
		
		.content{
			width: 90%;
			margin: 0 auto;
			margin-top: 40rpx;
			background: #373D52;
			border-radius: 30rpx;
			
			.top{
				height: 64rpx;
				line-height: 64rpx;
				background: linear-gradient(90deg,rgba(255, 255, 255, 0.05),rgba(255, 255, 255, 0.60));
				
				image{
					width: 32rpx;
					height: 32rpx;
					margin-left: 24rpx;
					margin-right: 20rpx;
					margin-top: 16rpx;
				}
				
				.title{
					font-size: 24rpx;
					color: #FFFFFF;
				}
			}
			
			.bottom{
				margin-top: 20rpx;
				
				.list{
					width: 50%;
					padding-left: 40rpx;
					padding-right: 30rpx;
					box-sizing: border-box;
					margin-bottom: 20rpx;
					
					.zuo{
						
						.name{
							font-size: 24rpx;
							color: #FFF0D9;
							margin-bottom: 12rpx;
						}
						
						.money{
							font-size: 40rpx;
							color: #FFF0D9;
							
							text{
								font-size: 24rpx;
								color: #FFF0D9;
								display: inline-block;
								margin-left: 8rpx;
							}
						}
					}
					
					.you{
						margin-top: 28rpx;
						
						image{
							width: 60rpx;
							height: 60rpx;
						}
					}
				}
			}
		}
		
		.nav{
			width: 90%;
			margin: 0 auto;
			margin-top: 40rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			padding-bottom: 20rpx;
			
			.top{
				height: 80rpx;
				line-height: 80rpx;
				
				image{
					width: 36rpx;
					height: 32rpx;
					margin-left: 28rpx;
					margin-right: 14rpx;
					margin-top: 26rpx;
				}
				
				.title{
					font-size: 24rpx;
					color: #333333;
				}
			}
			
			.fenlei{
				width: 96%;
				margin: 20rpx auto 0;
				
				.li{
					width: 33.3%;
					text-align: center;
					margin-bottom: 20rpx;
					
					image{
						width: 72rpx;
						height: 72rpx;
					}
					
					.title{
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}
	}
</style>